package com.mgkj.common.utils.yf;


import cn.hutool.core.util.NumberUtil;
import com.mgkj.dto.yf.InitRaxDto;
import com.mgkj.vo.yf.InitRaxVo;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class InitMoneyUtils {

    public static InitRaxVo getRax(InitRaxDto initRaxDto) {
        InitRaxVo vo = new InitRaxVo();
        BigDecimal price = NumberUtil.mul(initRaxDto.getNums(), initRaxDto.getUnitPrice());
        vo.setPrice(NumberUtil.round(price, 2));
        // 1应税内含  2应税外加  3零税率
        switch (initRaxDto.getType()) {
            case "1":
                vo.setPriceBeforeTax(NumberUtil.div(price, NumberUtil.add(1, initRaxDto.getRax()), 2, RoundingMode.HALF_UP));
                vo.setTaxPrice(NumberUtil.round(NumberUtil.sub(price, vo.getPriceBeforeTax()), 2));
                vo.setTaxPriceLocal(NumberUtil.round(NumberUtil.mul(vo.getTaxPrice(), initRaxDto.getExchangeRate()), 2));
                vo.setPriceBeforeTaxLocal(NumberUtil.round(NumberUtil.mul(vo.getPriceBeforeTax(), initRaxDto.getExchangeRate()), 2));
                vo.setPriceLocal(NumberUtil.round(NumberUtil.add(vo.getTaxPriceLocal(), vo.getPriceBeforeTaxLocal()), 2));
                break;
            case "2":
                vo.setPriceBeforeTax(vo.getPrice());
                vo.setTaxPrice(NumberUtil.round(NumberUtil.mul(initRaxDto.getRax(), price), 2));

                vo.setTaxPriceLocal(NumberUtil.round(NumberUtil.mul(vo.getTaxPrice(), initRaxDto.getExchangeRate()), 2));
                vo.setPriceBeforeTaxLocal(NumberUtil.round(NumberUtil.mul(vo.getPriceBeforeTax(), initRaxDto.getExchangeRate()), 2));
                vo.setPriceLocal(NumberUtil.round(NumberUtil.add(vo.getTaxPriceLocal(), vo.getPriceBeforeTaxLocal()), 2));
                break;
            case "3":
            case "4":
            case "9":
                vo.setPriceBeforeTax(vo.getPrice());
                vo.setTaxPrice(new BigDecimal(0));
                vo.setTaxPriceLocal(new BigDecimal(0));
                vo.setPriceLocal(NumberUtil.round(NumberUtil.mul(vo.getPrice(), initRaxDto.getExchangeRate()), 2));
                vo.setPriceBeforeTaxLocal(NumberUtil.round(NumberUtil.mul(vo.getPriceBeforeTax(), initRaxDto.getExchangeRate()), 2));
                break;
        }
        return vo;
    }

}
